const express = require('express');
const router = express.Router();
const db = require('../../../util/dbConfig/dbConfig')


router.post('/',async (req,res) => {
    let {
        id,     //羊只编号
        row,    //选项 0.体重 1.体高 2.体长 3.胸围 4.绒长度 5.绒细度 6.绒产量 7.管围 8.绒厚
    }=req.body
    if(!id){
        return res.send({
            code: 1,
            msg: '参数错误'
        })
    }
    let decArr = [
        'WEIGHT',
        'BODYTALL',
        'BODYLONG',
        'CHEST',
        'LENGTH',
        'FINE',
        'RONGYIELD',
        'PIPE',
        'TINCK_WOOL'
    ]
    row = row?Number(row):0
    try{
        let sql = `select ${decArr[row]},YEAR from production where SHEEP_ID=${id} order by YEAR `
        let result = await db.SySqlConnect(sql,[])
        if(result.length ===  0){
            return res.send({
                code: 2,
                msg: '无查询信息'
            })
        }
        return res.send({
            code: 0,
            msg: `查询成功${result.length}条数据`,
            result
        })
    }catch (e) {
        console.log(e);
        return res.send({
            code: 4,
            msg: '服务器错误，请稍后再试'
        })
    }
})


module.exports = router
